styleproperty: Let parse_value() initialize the value
authorBenjamin Otte <otte@redhat.com>
Mon, 2 Jan 2012 09:06:47 +0000 (10:06 +0100)
committerBenjamin Otte <otte@redhat.com>
Mon, 9 Jan 2012 17:37:54 +0000 (18:37 +0100)
... and document that behavior.

gtk/gtkcssprovider.c
gtk/gtkcssshorthandproperty.c
gtk/gtkcssstyleproperty.c
gtk/gtkstyleproperty.c

index 9943814950d0142e33dbd2198ec6a62c5efe21f4..b6cb329fce2fa168b55a83739f7553367fdd6a9c 100644 (file)
@@ -2353,7 +2353,6 @@ parse_declaration (GtkCssScanner *scanner,
       gtk_css_scanner_push_section (scanner, GTK_CSS_SECTION_VALUE);
 
       val = property_value_new (scanner->section);
-      g_value_init (&val->value, _gtk_style_property_get_value_type (property));
 
       if (_gtk_style_property_parse_value (property,
                                            &val->value,
index 2c6906b9b25342245fc2f9c997af00905053bb0d..8258c001f4a051d88a127fa2892ff4ebd8535a68 100644 (file)
@@ -153,7 +153,6 @@ gtk_css_shorthand_property_parse_value (GtkStyleProperty *property,
       g_value_set_enum (val, GTK_CSS_INITIAL);
     }
 
-  g_value_unset (value);
   g_value_init (value, G_TYPE_VALUE_ARRAY);
   g_value_set_boxed (value, array);
   return TRUE;
index b7c7afedf715d9078a7b5ab1ff21e22e799ee5ba..62323738563aedd18c7b2852e0547632ade21775 100644 (file)
@@ -324,12 +324,13 @@ gtk_css_style_property_parse_value (GtkStyleProperty *property,
                                     GtkCssParser     *parser,
                                     GFile            *base)
 {
+  gboolean success;
+
   if (_gtk_css_parser_try (parser, "initial", TRUE))
     {
       /* the initial value can be explicitly specified with the
        * â€˜initial’ keyword which all properties accept.
        */
-      g_value_unset (value);
       g_value_init (value, GTK_TYPE_CSS_SPECIAL_VALUE);
       g_value_set_enum (value, GTK_CSS_INITIAL);
       return TRUE;
@@ -342,7 +343,6 @@ gtk_css_style_property_parse_value (GtkStyleProperty *property,
        * strengthen inherited values in the cascade, and it can
        * also be used on properties that are not normally inherited.
        */
-      g_value_unset (value);
       g_value_init (value, GTK_TYPE_CSS_SPECIAL_VALUE);
       g_value_set_enum (value, GTK_CSS_INHERIT);
       return TRUE;
@@ -351,22 +351,31 @@ gtk_css_style_property_parse_value (GtkStyleProperty *property,
     {
       GError *error = NULL;
       char *value_str;
-      gboolean success;
       
       value_str = _gtk_css_parser_read_value (parser);
       if (value_str == NULL)
         return FALSE;
       
+      g_value_init (value, _gtk_style_property_get_value_type (property));
       success = (*property->property_parse_func) (value_str, value, &error);
 
       g_free (value_str);
+      if (!success)
+        g_value_unset (value);
 
       return success;
     }
-  else if (property->parse_func)
-    return (* property->parse_func) (parser, base, value);
+
+  g_value_init (value, _gtk_style_property_get_value_type (property));
+  if (property->parse_func)
+    success = (* property->parse_func) (parser, base, value);
   else
-    return _gtk_css_style_parse_value (value, parser, base);
+    success = _gtk_css_style_parse_value (value, parser, base);
+
+  if (!success)
+    g_value_unset (value);
+
+  return success;
 }
 
 static void
index 4bc9c38d6f17c858a71e4800b254707263b68ca6..b181be90650593af89a54278398f64375bf7701e 100644 (file)
@@ -379,6 +379,25 @@ border_corner_radius_value_print (const GValue *value,
 
 /*** API ***/
 
+/**
+ * _gtk_style_property_parse_value:
+ * @property: the property
+ * @value: an uninitialized value
+ * @parser: the parser to parse from
+ * @base: the base file for @aprser
+ *
+ * Tries to parse the given @property from the given @parser into
+ * @value. The type that @value will be assigned is dependant on
+ * the parser and no assumptions must be made about it. If the
+ * parsing fails, %FALSE will be returned and @value will be
+ * left uninitialized.
+ *
+ * Only if @property is a #GtkCssShorthandProperty, the @value will
+ * always contain a #GValueArray with the values to be used for
+ * the subproperties.
+ *
+ * Returns: %TRUE on success
+ **/
 gboolean
 _gtk_style_property_parse_value (GtkStyleProperty *property,
                                  GValue           *value,